package com.ruoyi.backend.controller.orderManagement;

import com.ruoyi.backend.domain.orderManagement.Order;
import com.ruoyi.backend.service.orderManagement.IRepairOrderService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修订单Controller
 *
 * @author 王冰冰
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/repairOrder")
public class RepairOrderController extends BaseController {
    @Autowired
    private IRepairOrderService iRepairOrderService;

    /**
     * 查询维修订单列表
     */
    @RequiresPermissions("orderManagement:repairOrder:list")
    @GetMapping("/list")
    public TableDataInfo list(Order order) {
        startPage();
        List<Order> list = iRepairOrderService.selectOrderMList(order);
        return getDataTable(list);
    }

    /**
     * 导出维修订单列表
     */
    @RequiresPermissions("orderManagement:repairOrder:export")
    @Log(title = "维修订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Order order) {
        List<Order> list = iRepairOrderService.selectOrderMList(order);
        ExcelUtil<Order> util = new ExcelUtil<>(Order.class);
        util.exportExcel(response, list, "维修订单数据");
    }

    /**
     * 获取维修订单详细信息
     */
    @RequiresPermissions("orderManagement:repairOrder:query")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return success(iRepairOrderService.selectOrderMByOrderId(orderId));
    }

    /**
     * 新增维修订单
     */
    @RequiresPermissions("orderManagement:repairOrder:add")
    @Log(title = "维修订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        return toAjax(iRepairOrderService.insertOrderM(order));
    }

    /**
     * 修改维修订单
     */
    @RequiresPermissions("orderManagement:repairOrder:edit")
    @Log(title = "维修订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return toAjax(iRepairOrderService.updateOrderM(order));
    }

    /**
     * 删除维修订单
     */
    @RequiresPermissions("orderManagement:repairOrder:remove")
    @Log(title = "维修订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(iRepairOrderService.deleteOrderMByOrderIds(orderIds));
    }
}